﻿@* DXCOMMENT: Configure GridView *@
	@{ var gridView = Html.DevExpress().GridView(
            settings =>
            {
                settings.Name = "NMCGridView";
                settings.CallbackRouteValues = new { Controller = "NMCTerritory", Action = "NMCTerritoryGrid" };
                settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "NMCTerritory", Action = "Save" };
               // settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "NMCTerritory", Action = "Delete" };
        
                settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
                //settings.SettingsPager.Visible = true;
                settings.SettingsPager.PageSize = 200;
                settings.Settings.ShowVerticalScrollBar = true;
                settings.Settings.VerticalScrollableHeight = 850;
                settings.SettingsBehavior.ConfirmDelete = true;
        
                settings.ControlStyle.Paddings.Padding = System.Web.UI.WebControls.Unit.Pixel(0);
                settings.ControlStyle.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
                settings.ControlStyle.BorderBottom.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
        
		        // DXCOMMENT: Configure grid's columns in accordance with data model fields
                var operationsColumn = new MVCxGridViewCommandColumn { Caption = "Options" };

                settings.Columns.Add(operationsColumn);
                operationsColumn.Width = System.Web.UI.WebControls.Unit.Pixel(96);
                //operationsColumn.DeleteButton.Visible = true;
                operationsColumn.EditButton.Visible = true;
                operationsColumn.Visible = true;
        
                settings.Columns.Add(col =>
                {
                    col.FieldName ="TerritoryName";
                    col.Caption = "Territory";
                    col.ColumnType = MVCxGridViewColumnType.TextBox;
                });
        
                settings.Columns.Add(col =>
                {
                    col.FieldName = "AccountTypeName";
                    col.Caption = "Account Type";
                    col.ColumnType = MVCxGridViewColumnType.ComboBox;
            
                    var comboBoxProperties = col.PropertiesEdit as ComboBoxProperties;
                    comboBoxProperties.DataSource = 
                        ((IEnumerable<String>)ViewBag.AccountTypes);
                });
        
                settings.Columns.Add(col =>
                {
                    col.FieldName = "NMCName";
                    col.Caption = "NMC Name";
                    col.ColumnType = MVCxGridViewColumnType.ComboBox;
            
                    var comboBoxProperties = col.PropertiesEdit as ComboBoxProperties;
                    comboBoxProperties.DataSource = 
                        ((IEnumerable<String>)ViewBag.NMCs);
                });

                settings.Columns.Add(col =>
                {
                    col.FieldName = "NMCTerritoryGLAccount";
                    col.Caption = "NMC GL Account";
                    col.ColumnType = MVCxGridViewColumnType.TextBox;

                });
        
                settings.Columns.Add(col =>
                {
                    col.FieldName = "LastModified";
                    col.Caption = "Last Modified By";
                    col.ColumnType = MVCxGridViewColumnType.TextBox;
                });

                settings.SettingsEditing.Mode = GridViewEditingMode.Inline;
                settings.KeyFieldName = "ID";
            });

            if (ViewData.ContainsKey("Error") && !String.IsNullOrWhiteSpace(ViewData["Error"].ToString()))
            {  gridView.SetEditErrorText(ViewData["Error"].ToString());}
    
            gridView.Bind(Model).GetHtml();
}